    // 获取元素
    let $userName = $('#userName');
    let $detail = $('#detail');
    let $btn = $('.btn');


    // 获取后台资源,渲染页面
    $.ajax({
        url: "http://localhost:3000/db",
        type: 'GET',
        dataType: "json",
        success: function(data) {
            // console.log(data);
            $('.messageInfo').html(template('tem', data));
            getDelete();
        }
    });
    //发送事件
    $btn.click(function() {
        //  动态获取时间
        let date = new Date();
        let h = date.getHours();
        h = h < 9 ? ' 0' + h : h
        let m = date.getMinutes();
        m = m < 9 ? '0' + m : m
        let s = date.getSeconds();
        s = s < 9 ? '0' + s : s;
        console.log(`${h}:${m}:${s}`);
        let time = `${h}:${m}:${s}`;
        // 动态获取input框里的值
        let userName = $userName.val();
        let content = $detail.val();
        $.ajax({
            url: "http://localhost:3000/comments",
            type: 'POST',
            dataType: 'json',
            data: {
                userName,
                content,
                time
            },
            success: function(data) {
                $('.messageInfo').append(template('tem', {
                    'comments': [data]
                }));
                getDelete()
            }
        });

        $userName.val('');
        $detail.val('');
    });

    function getDelete() {
        $('.del').click(function() {
            let $li = $(this).parents('li')
            let index = $li.attr('uId');
            // console.log(index);
            $.ajax({
                url: 'http://localhost:3000/comments/' + index,
                type: 'DELETE'
            })
            $li.remove();
        })
    }